package com.googlecode.icecube.push;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.googlecode.icefusion.ui.commons.BackingBeanForm;
import com.googlecode.icefusion.ui.commons.push.IProgressDialog;
import com.googlecode.icefusion.ui.commons.push.ProgressDialog;


/**
 * Manage progress dialog examples.
 * 
 * @author Rainer Eschen
 * 
 */
public class PopupProgressDialog extends BackingBeanForm implements IProgressDialog {

    private static final long serialVersionUID = 6358063542606784658L;

    @Autowired
    @Qualifier("progressDialog")
    private ProgressDialog progressDialog;

    /**
     * Progress management.
     */
    Long progress = 0L;

    /**
     * Cancel button management.
     */
    Boolean cancel = false;

    /**
     * @see com.googlecode.icefusion.ui.commons.push.IProgressDialog#getCancel()
     */
    public Boolean getCancel() {

        return this.cancel;
    }

    /**
     * @see com.googlecode.icefusion.ui.commons.push.IProgressDialog#getProgress()
     */
    public Long getProgress() {

        // The progress dialog is waiting one second before the next update
        // is processed. So, with this increment we have a 10 seconds presentation.
        this.setProgress(this.progress + 10);
        return this.progress;
    }

    /**
     * @see com.googlecode.icefusion.ui.commons.push.IProgressDialog#setCancel(java.lang.Boolean)
     */
    public void setCancel(Boolean cancel) {

        this.cancel = cancel;
    }

    /**
     * @see com.googlecode.icefusion.ui.commons.push.IProgressDialog#setProgress(java.lang.Long)
     */
    public void setProgress(Long progress) {

        this.progress = progress;

    }

    /**
     * Button to start progress dialog.
     * 
     * @return navigationId
     */
    public String progress() {

        this.setProgress(0L);
        this.progressDialog.startProcess(this);
        return null;
    }

}
